﻿using UnityEngine;

public  class UIBlurMgr : Singleton<UIBlurMgr>
{
    private int UIBlurLayer;
    private int UIUnBlurLayer;
    private int blurNum;
    private BlurEffect blurEff;

    public UIBlurMgr()
    {
        UIBlurLayer = LayerMask.NameToLayer("UI");
        UIUnBlurLayer = LayerMask.NameToLayer("UnBlur");
        blurEff = AllUpdate.Camer2D.GetComponent<BlurEffect>();
    }
    
    public bool IsOpen
    {
        get { return blurEff.enabled; }
    }

    public void AddBlur()
    {
        blurNum++;
        Refresh();

    }

    public void RemoveBlur()
    {
        blurNum--;
        Refresh();
    }

    private void Refresh()
    {
        blurEff.enabled = blurNum > 0;
    }
    
    public void AddUnBlur(GameObject go)
    {
        go.layer = UIUnBlurLayer;
        NGUITools.SetChildLayer(go.transform, UIUnBlurLayer);
    }

    public void RemoveUnBlur(GameObject go)
    {
        go.layer = UIBlurLayer;
        NGUITools.SetChildLayer(go.transform, UIBlurLayer);
    }
}